package cz.cernilovsky.android.profileapp.model;

import android.content.Context;
import android.media.AudioManager;

public class SoundsAction extends Action {

	public SoundsAction(Operation typeOfAction) {
		super(typeOfAction);
	}

	@Override
	public boolean perform(Context context) {
		if(operation != Operation.NOOP) {
			AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
			if(
				(am.getRingerMode() == AudioManager.RINGER_MODE_NORMAL && operation == Operation.OFF)
					|| (
							(am.getRingerMode() == AudioManager.RINGER_MODE_SILENT || am.getRingerMode() == AudioManager.RINGER_MODE_VIBRATE)
							&& operation == Operation.ON
						)
				) {
				am.setRingerMode(operation == Operation.ON ? AudioManager.RINGER_MODE_NORMAL : AudioManager.RINGER_MODE_VIBRATE);
				return true;
			}
		}
		return false;
	}

}
